package com.qf.pickname.service.impl;

import com.qf.pickname.dao.StudentDao;
import com.qf.pickname.entity.Student;
import com.qf.pickname.service.StudentService;
import com.qf.pickname.utils.StudentDataStore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Random;

// 添加该注解，会让springboot启动时扫描到当前类，并且帮我们创建这个类的对象
@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    private StudentDao studentDao;

    @Override
    public Student randomStudent() {
        Random random = new Random();
        Integer count = studentDao.getStudentCount();
        int index = random.nextInt(count);
        Student student = studentDao.getStudentByIndex(index);
        return student;
    }
}
